package com.example.cloudservicea.controller;

import com.example.cloudservicea.dto.UserDTO;
import com.example.cloudservicea.pojo.User;
import com.example.cloudservicea.service.IUserService;
import com.example.cloudservicea.util.CommonBeanUtils;
import org.lanqiao.cloudcommon.common.CommonResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
public class UserController {


    @Autowired
    IUserService userService;

    @GetMapping("/users")
    public CommonResult test(){
      return  CommonResult.SUCCESS("我是微服务A中的/users");

    }

    /**
     * 该接口主要提供给servce-b
     * @param id
     * @return
     */
    @GetMapping("/users/{id}")
    public    CommonResult<UserDTO>  findById(@PathVariable("id") String  id ){
        User user = userService.getById(id);
        UserDTO   dto  =  CommonBeanUtils.transformObject(user,UserDTO.class);
        return  CommonResult.SUCCESS("远程调用用户成功",dto);

    }






}
